from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
import sys
import os

# 添加当前目录到Python路径
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from app.api.v1 import auth, users, chats, ai_characters, moments, payments, advertisements

app = FastAPI(
    title="AI虚拟社交APP API",
    description="AI虚拟社交APP的后端API接口",
    version="1.0.0",
    docs_url="/docs",
    redoc_url="/redoc",
    openapi_url="/openapi.json"
)

# 配置CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 注册路由
app.include_router(auth.router, prefix="/api/v1/auth", tags=["auth"])
app.include_router(users.router, prefix="/api/v1/users", tags=["users"])
app.include_router(chats.router, prefix="/api/v1/chats", tags=["chats"])
app.include_router(ai_characters.router, prefix="/api/v1/ai-characters", tags=["ai-characters"])
app.include_router(moments.router, prefix="/api/v1/moments", tags=["moments"])
app.include_router(payments.router, prefix="/api/v1/payments", tags=["payments"])
app.include_router(advertisements.router, prefix="/api/v1/advertisements", tags=["advertisements"])

@app.get("/")
async def root():
    return {"message": "Welcome to AI虚拟社交APP API"}

@app.get("/health")
async def health_check():
    return {"status": "healthy"}

if __name__ == "__main__":
    # 获取当前文件的目录
    current_dir = os.path.dirname(os.path.abspath(__file__))
    # 切换到当前目录
    os.chdir(current_dir)
    uvicorn.run("app.main:app", host="127.0.0.1", port=8000, reload=True)
